<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <section id="app">
        <header class="header">
            <h1>小黑记事本</h1>
            <input type="text" placeholder="请输入任务" v-model="toName">
            <button @click="add">添加任务</button>
        </header>
        <section class="main">
            <ul class="todo-list">
                <li class="todo" v-for="(item,index) in list" :key="(item,index)">
                    <div class="view">
                        <span class="index">{{ index +1}}</span>
                        <button @click="del(item,id)" class="destory"></button>
                    </div>
                </li>
            </ul>
            <footer class="footer">
                <span class="todo-count">合计:</span>
                <button class="clear-completed">

                </button>
            </footer>
        </section>
    </section>
    <script src="./vue.js"></script>
    <script>
        const app=new  Vue({
            el:"#app",
            data:{
                todoName:"",
                list:[
                    {id: 1,name: "跑步一公里"},
                    {id: 2,name: "跳绳200个"}
                ]
            },
            methods:{
                del (id){
                    this.list=this.list.filter(item =>item.id !=id)
                },
                add(){
                    this.list.unshift({
                        id: +new Date,
                        name: this.todoName
                    })
                }
            }
        })
    </script>
</body>

</html>